#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2020/11/24 11:55
# @Author  : LuLu
# @FileName: tourguideDestinationPage.py
# @Software: PyCharm

from time import sleep
from page import basePage
from pagesLocators.navigationLocators import NavigationLoc
from pagesLocators.tourguideDestinationLocators import TourGuideDestinationLoc as Loc


# from pagesLocators.selectBoxLocators import selectBoxLoc as selectLoc


class TourGuideDestination(basePage.BasePage):

    # 点击新增目的地按钮
    def click_add_button(self):
        self.click_element(Loc.add_button)

    # 点击顶部多选删除按钮
    def click_delete_button(self):
        self.click_element(Loc.choice_delete_button)
        sleep(0.5)
        self.click_element(Loc.delete_yes)

    # 点击单个编辑框
    def click_one_edit(self, num):
        self.click_element(Loc.edit_one_button(num))
        sleep(2)

    # 点击单个删除按钮
    def click_one_delete(self, num):
        self.click_element(Loc.delete_one_button(num))
        sleep(0.5)
        self.click_element(Loc.delete_yes)

    # 删除成功提示
    def get_toast_warn(self):
        return self.get_element_value(Loc.toast_warn) == '删除成功'

    # 获取表格rows行内容
    def get_table_rows(self, start_row=1, row_num=None):
        return self.get_table_row(Loc.destination_list_table, start_row, row_num)

    # 获取某行是否勾选
    def get_rows_is_selected(self, row=1):
        return 'selected' == self.get_element_attribute(Loc.one_rows(row), 'class')

    # 获取表格lines列内容
    def get_table_lines(self, start_line=1, line_num=None):
        return self.get_table_line(Loc.destination_list_table, start_line, line_num)

    """新增编辑框内容操作"""

    # 窗口title
    def get_destination_Window_title(self):
        return self.get_element_value(Loc.destination_title)

    # 目的地名称
    def sendKey_destination_name(self, value):
        self.clear_and_sendKey_element(Loc.destination_name, value)

    def get_destination_name(self):
        # text 输入方式的，get_value获取不到
        return self.get_element_attribute(Loc.destination_name, 'value')

    # 目的地长度限制
    def get_destination_length_limits(self):
        return self.get_element_value(Loc.destination_length_limits)

    # 目的地排序
    def sendKey_destination_sorted(self, value):
        self.clear_and_sendKey_element(Loc.destination_sorted, value)

    def get_destination_sorted(self):
        return self.get_element_attribute(Loc.destination_sorted, 'value')

    # 移动问号
    def move_question_mark(self):
        self.move_to_element(Loc.question_mark)

    # 问号提示内容
    def get_question_mark_content(self):
        return self.get_element_value(Loc.question_mark_content)

    # def uplpad_logo(self, sleep_time=2, *fileName):
    #     sleep(sleep_time)
    #     self.click_element(Loc.destination_Logo_button)
    #     sleep(sleep_time)
    #     self.uploading_picture(*fileName)

    # logo 是否上传成功
    def is_upload_success(self):
        return self.isElementExist(Loc.destination_Logo_upload_success)

    # 删除logo
    def delete_logo(self):
        self.click_element(Loc.close_logo_button)

    # 获取上传大小提示
    def get_upload_warn(self):
        return self.get_element_value(Loc.upload_warn)

    # 输入目的地poi名称，用于关联查询列表
    def sendKey_poi_name(self, value):
        self.clear_and_sendKey_element(Loc.poi_edit_input, value)

    #  从下拉列表选择poi地址
    def select_poi(self, num=1):
        sleep(1)
        self.click_element(Loc.poi_edit_select_one(num))

    #  从下拉列表删除poi地址
    def delete_poi(self, num=1):
        sleep(0.3)
        self.click_element(Loc.poi_edit_delete_one(num))

    # 获取已选择的poi地址
    def get_poi_list(self):
        return self.get_element_value(Loc.poi_edit_box).split("\n")

    # 下拉选择列表条数 ：10
    def get_select_poi_list_length(self):
        sleep(3)
        return len(self.get_element_value(Loc.poi_edit_select_box).split("\n"))

    # 点击提交按钮
    def click_commit_button(self):
        sleep(1)
        self.click_element(Loc.commit_button)
        # self.driver.execute_script('arguments[0].click()', Loc.commit_button)

    # 点击取消按钮
    def click_cancel_button(self):
        self.click_element(Loc.cancel_button)

    # 点击关闭弹层
    def click_close_laye(self):
        self.click_element(Loc.close_laye)

    # 获取名字提示框
    def destination_name_warn(self):
        return self.get_element_value(Loc.destination_name_warn)

    # 获取排序提示框
    def destination_sorted_warn(self):
        return self.get_element_value(Loc.destination_sorted_warn)

    # 获取POI提示框
    def destination_POI_warn(self):
        return self.get_element_value(Loc.destination_POI_warn)

    # 获取LOGO提示框
    def destination_LOGO_warn(self):
        return self.get_element_value(Loc.destination_LOGO_warn)

    # 创建一个佛山市的封装-测试方法
    def add_TourGuideDestination_success(self):
        try:
            self.click_add_button()
            self.sendKey_destination_name('佛山市')
            self.sendKey_destination_sorted('999a999')
            if self.isElementExist(Loc.destination_name_warn):
                if self.destination_name_warn() == '目的地名称已存在，请重新填写':
                    self.click_close_laye()
                    return
            self.sendKey_poi_name('佛山市')
            sleep(1)
            self.select_poi(1)
            self.uploading_picture(Loc.destination_Logo_button, '佛山.png')
            self.click_commit_button()
            sleep(1.5)
        except Exception as e:
            raise e
